********************************************************************************
***																			****
***		Firm Survey Descriptive Statistics									****
********************************************************************************
/*

Author: Lala Rukh Khan
Date created: 21 January 2020
Last edited by: Lala Rukh Khan
Last edited: 31 January 2020

Purpose: Summary statistics on Firm Survey data, generating graphs and tables


	(0) Settings
	(1) Basic Stats on the Firms Approached
		(a) Registration Status
		(b) Industry Classification
		(c) Firm Space
	(2) Comparison of firms that signed up and did not sign up
		(a) Industry Classification
		(b) Firm Space
		(c) Turnover
		(d) Average Employee Size
		(e) Women's Comfort By Sign ups
	(3)	Transportation
		(a) Transport Mode used by Employees
		(b) Consider transport mode and residence
		(c) Provide pick and drop service
		(d) Consider contributing to pick and drop service
	(4) Female Employees
		(a) Share of Female Employees by Firm Size
		(b) Ads placed for women & firm composition
		(c) Female Preference for Ads and Firm Size
	(5) Vacancies
		(a) Recruitment Methods
	(6) Comparison of Recent Vacancy & Adlisting
		(a) Education
		(b) Experience
		(c) Salary
		
		
	IN PERSON SURVEY
*/

********************************************************************************
*					(0) Settings and globals
********************************************************************************
clear
 
run "C:\Users\CERP\Dropbox (CERP)\WMP dofiles\Data Preparation + Visualizations\scripts\settings.do"

global shades5 "bar(1, color(green) fintensity(inten200) lcolor(white)) bar(2, color(green) fintensity(inten100) lcolor(white)) bar(3, color(green) fintensity(inten70) lcolor(white)) bar(4, color(green) fintensity(inten50) lcolor(white)) bar(5, color(green) fintensity(inten30) lcolor(white)) bar(6, color(green) fintensity(inten20) lcolor(white)) bar(7, color(green) fintensity(inten10) lcolor(white))" 

global shades6 "bar(1, color(cranberry) fintensity(inten200) lcolor(white)) bar(2, color(cranberry) fintensity(inten100) lcolor(white)) bar(3, color(cranberry) fintensity(inten70) lcolor(white)) bar(4, color(cranberry) fintensity(inten50) lcolor(white)) bar(5, color(cranberry) fintensity(inten30) lcolor(white)) bar(6, color(cranberry) fintensity(inten20) lcolor(white)) bar(7, color(cranberry) fintensity(inten10) lcolor(white))" 

global shades7 "bar(1, color(navy) fintensity(inten200) lcolor(white)) bar(2, color(navy) fintensity(inten100) lcolor(white)) bar(3, color(navy) fintensity(inten70) lcolor(white)) bar(4, color(navy) fintensity(inten50) lcolor(white)) bar(5, color(navy) fintensity(inten30) lcolor(white)) bar(6, color(navy) fintensity(inten20) lcolor(white)) bar(7, color(navy) fintensity(inten10) lcolor(white))" 	
	
global shades8 "bar(1, color(navy) fintensity(inten300) lcolor(white)) bar(2, color(navy) fintensity(inten200) lcolor(white)) bar(3, color(navy) fintensity(inten100) lcolor(white)) bar(4, color(navy) fintensity(inten50) lcolor(white)) bar(5, color(navy) fintensity(inten30) lcolor(white))" 	



**********************************************************************************
*				(1) Basic Stats on the Firms Approached
*********************************************************************************
* (a) Registration Status
use "$anon_data\3ie Deliverable Datasets\FS_survey_public.dta", clear
	keep if inlist(EB_type, 2)							// geographic sample only
	
	gen resp=1 if inlist(reg_status, 1, 9)					// respondent variable
		replace resp=0 if resp==.
		
	drop if inlist(firm_status_cons, 3)						// dropping permanently closed firms

preserve

drop if inlist(reg_status, 8, 10)
replace reg_status=2 if inlist(reg_status, 3, 4, 5, 6, 7)
gen freq=1
count
local nb_obs=`r(N)'
graph hbar (percent) freq, over(reg_status, label(labsize(vsmall))) nofill ///
graphregion(color(white)) $shades6 ///
blabel(total, position(outside) format(%5.1f) color(black)  size(vsmall)) ///
	 title("Registration Status", size(medium)) ///
	subtitle("N = `nb_obs'", size(small)) ytitle("percentage") ///
	note("{it: Note: 'Successful' refers to those firms that signed up or filled the survey or answered research questions}", size(vsmall))
	graph export "$graph_out\Firm Survey\Graphs\reg_status.png", as(png) replace width(2400) height(1800)	
restore


* (b) Industry Classification


preserve
count if !inlist(industry_classification, 22, .)
	local nb_obs = `r(N)'
	gen nb_obs = `r(N)'
count if !inlist(industry_classification, 22, .) & resp == 1
	local res =`r(N)'
count if !inlist(industry_classification, 22, .) & resp == 0
	local nres =`r(N)'
replace industry_classification =. if industry_classification==22 // can't decide which industry
foreach i of numlist 1/21 {
			gen indclass_`i' = 0
			replace indclass_`i'=. if industry_classification ==.
			replace indclass_`i' = 1 if industry_classification==`i'
			}
			 
			foreach i of numlist 1/21 {
			count if indclass_`i'==1
			gen tindclass_`i'=`r(N)'
			count if indclass_`i'==1 & resp==1
			gen indclass_meanres`i' = (`r(N)'/tindclass_`i')*100
			}
			
			foreach i of numlist 1/21 { 
			count if (indclass_`i'==1 & resp==0)
			gen indclass_meannotr`i' = (`r(N)'/tindclass_`i')*100
			}
			
			foreach i of numlist 1/21 { 
			sum indclass_`i'
			gen indclass_mean`i' = `r(mean)'*100
			}
			
			keep indclass_mean*
			duplicates drop

			gen helper = 1
			reshape long indclass_mean indclass_meanres indclass_meannotr, i(helper) j(industry)
			
			replace industry=23 if indclass_mean<1
		label list industry_classification
			label define industry_forgraph 1 "Agricultural act" ///
			2 "Mining, quarrying" 3 "Manufacturing"  4 "Electricity, gas, etc." ///
			5 "Water, sewerage, waste management etc." 6 "Construction" ///
			7 "Wholesale, retail trade, repair vehicles" 8 "Transportation, storage" ///
			9 "Accommodation, food service act." 10 "Information, communication" ///
			11 "Financial, insurance act." 12 "Real estate act." 13 "Scientific, technical act." ///
			14 "Admin, support service act." 15 "Public admin, defence" 16 "Education" ///
			17 "Human health, social work act." 18 "Arts & entertainment" 19 "Other service act." ///
			20 "Household act." 21 "Extraterritorial organ act." 23 "Others"

			label values industry industry_forgraph
			
		graph hbar indclass_mean, over(industry, label(labsize(vsmall))) ///
				graphregion(color(white)) $shades5  blabel(total, position(outside) format(%5.1f) color(black)  size(vsmall)) ///
				title("Industry Classification", size(medium)) ///
				subtitle("In Person Survey (Representative Sample) N = `nb_obs'", size(small)) ytitle("percentage") ///
				note("{it: Note: Question: Based only on your observation from outside the firm, which industry classification}" "{it: best describes this organization?}", size(vsmall))
				graph export "$graph_out\Firm Survey\Graphs\industry_listed.png", as(png) replace width(2400) height(1800)

		graph hbar indclass_meanres indclass_meannotr, over(industry, label(labsize(vsmall))) stack ///
				graphregion(color(white)) blabel(total, position(outside) format(%5.1f) color(white)  size(vsmall)) ///
				legend(label(1 "Respondents") label(2 "Non-Respondents")) ///
				title("Industry Classification by Respondent Types", size(medium)) ///
				subtitle("In Person Survey (Representative Sample) N = `nb_obs'", size(small)) ytitle("percentage") ///
				note("{it: Note: Question: Based only on your observation from outside the firm, which industry classification}" "{it: best describes this organization?}" ///
				"Total Nb of Respondents = `res', Total Nb of Non-Respondents = `nres'", size(vsmall))
				graph export "$graph_out\Firm Survey\Graphs\industry_byresptype.png", as(png) replace width(2400) height(1800)
			
restore


*(c) Firm Space

preserve
count if !inlist(estab_space, 8, .d, .l)
	local nb_obs = `r(N)'
	gen nb_obs = `r(N)'
count if !inlist(estab_space, 8, .d, .l) & resp == 1
	local res = `r(N)'
count if !inlist(estab_space, 8, .d, .l) & resp == 0
	local nres = `r(N)'

foreach i of numlist 1/7 {
			gen space`i' = 0
			replace space`i'=. if estab_space ==.
			replace space`i' = 1 if estab_space==`i'
			}
			 
			foreach i of numlist 1/7 { 
			count if space`i'==1
			gen tspace`i'=`r(N)'
			count if space`i'==1 & resp==1
			gen space_meanres`i' = (`r(N)'/tspace`i')*100
			count if space`i'==1 & resp==0
			gen space_meannotr`i' = (`r(N)'/tspace`i')*100
			sum space`i'
			gen space_mean`i' = `r(mean)'*100
			}
			
			
		
			keep space_mean*
			duplicates drop

			gen helper = 1
			reshape long space_mean space_meanres space_meannotr, i(helper) j(space)
			
		label list estab_space
			label define space_forgraph 1 "One room/ shop" 2 "Several rooms/ shops" ///
			3 "Half a floor in a building" 4 "One floor in a building" 5 "Several floors in a building" ///
           6 "An entire building" 7 "Several buildings"
			label values space space_forgraph
			
		graph hbar space_mean, over(space, label(labsize(vsmall))) ///
				graphregion(color(white)) blabel(total, position(outside) format(%5.1f) color(black)  size(vsmall)) ///
				$shades5 ///
				title("Firm Space", size(medium)) legend(label(1 "Respondents") label(2 "Non-Respondents")) ///
				subtitle("In Person Survey (Representative Sample) N = `nb_obs'", size(small)) ytitle("percentage") ///
				note("{it: Note: Question: ENUMERATOR: How much space does this establishment occupy?}", size(vsmall))
				graph export "$graph_out\Firm Survey\Graphs\space_listed.png", as(png) replace width(2400) height(1800)
		
		graph hbar space_meanres space_meannotr, over(space, label(labsize(vsmall))) stack ///
				graphregion(color(white)) blabel(total, position(outside) format(%5.1f) color(white)  size(vsmall)) ///
				title("Firm Space for Respondents and Non Respondents", size(medium)) legend(label(1 "Respondents") label(2 "Non-Respondents")) ///
				subtitle("In Person Survey (Representative Sample) N = `nb_obs'", size(small)) ytitle("percentage") ///
				note("{it: Note: Question: ENUMERATOR: How much space does this establishment occupy?}" ///
				"Total Nb of Respondents = `res', Total Nb of Non-Respondents = `nres'", size(vsmall))
				graph export "$graph_out\Firm Survey\Graphs\space_byresp_geo.png", as(png) replace width(2400) height(1800)
restore



******************************************************************************** 
*        (2) Comparison of firms that signed up and did not sign up
*******************************************************************************


* (a) Industry Classification

	preserve

	replace sig = 0 if signup_service == .
	
	distinct firm_id if sig == 1
		gen sig_tot =`r(N)'	
	
	distinct firm_id if sig == 0 
		gen nsig_tot =`r(N)'

	count if !inlist(industry_classification, 22, .)
		local nb_obs=`r(N)'

		replace industry_classification =. if industry_classification==22 // can't decide which industry
	foreach i of numlist 1/21 {
				gen indclass_`i' = 0
				replace indclass_`i'=. if industry_classification ==.
				replace indclass_`i' = 1 if industry_classification==`i'
				}
				 
				foreach i of numlist 1/21 { 
				count if indclass_`i'==1
				gen tindclass_`i'=`r(N)'
				count if indclass_`i'==1 & sig == 1
				gen indclass_means`i' = (`r(N)'/tindclass_`i')*100
				count if indclass_`i'==1 & sig == 0
				gen indclass_meann`i' = (`r(N)'/tindclass_`i')*100
				}
				
			
				keep indclass_mean*
				duplicates drop

				gen helper = 1
				reshape long indclass_means indclass_meann, i(helper) j(industry)
				replace industry=23 if indclass_means<1 & indclass_meann<1
			label list industry_classification
					label define industry_forgraph 1 "Agricultural act" ///
			2 "Mining, quarrying" 3 "Manufacturing"  4 "Electricity, gas, etc." ///
			5 "Water, sewerage, waste management etc." 6 "Construction" ///
			7 "Wholesale, retail trade, repair vehicles" 8 "Transportation, storage" ///
			9 "Accommodation, food service act." 10 "Information, communication" ///
			11 "Financial, insurance act." 12 "Real estate act." 13 "Scientific, technical act." ///
			14 "Admin, support service act." 15 "Public admin, defence" 16 "Education" ///
			17 "Human health, social work act." 18 "Arts & entertainment" 19 "Other service act." ///
			20 "Household act." 21 "Extraterritorial organ act." 23 "Others"

				label values industry industry_forgraph
				
			graph hbar indclass_means indclass_meann if (indclass_means!=. | indclass_meann!=.), over(industry, label(labsize(vsmall))) stack ///
					graphregion(color(white))  blabel(total, position(outside) format(%5.1f) color(white)  size(vsmall)) ///
					title("Industry Classification for Firms that Signed up &" "Did not Sign Up", size(medium)) ///
					subtitle("N (Representative Sample)= `nb_obs'", size(small)) ytitle("percentage") ///
					legend(label(1 "Sign Up") label(2 "Did not Sign Up")) ///
					note("{it: Note: Question: Based only on your observation from outside the firm, which industry classification}" "{it: best describes this organization?}" ///
					"This Sample only includes firms that were successfully reached", size(vsmall))
					graph export "$graph_out\Firm Survey\Graphs\ind_class_sign_comp.png", as(png) replace width(2400) height(1800)

restore

* (b) Firm Space 


preserve

	replace sig = 0 if signup_service == .
	

	count if !inlist(estab_space, 8, .d, .l)
		local nb_obs = `r(N)'
		
	count if !inlist(estab_space, 8, .d, .l) & sig == 0
		local nsign= `r(N)'
		
	count if !inlist(estab_space, 8, .d, .l) & signup_service==1
		local sign = `r(N)'

foreach i of numlist 1/7 {
			gen space`i' = 0
			replace space`i'=. if estab_space ==.
			replace space`i' = 1 if estab_space==`i'
			}
			 
			foreach i of numlist 1/7 { 
			count if space`i'==1
			gen tspace`i'=`r(N)'
			count if space`i'==1 & sig == 0
			gen space_meannosig`i' = (`r(N)'/tspace`i')*100
			count if space`i'==1 & signup_service==1
			gen space_meansig`i' = (`r(N)'/tspace`i')*100
			}
			
			keep space_mean*
			duplicates drop

			gen helper = 1
			reshape long space_meansig space_meannosig, i(helper) j(space)
			
		label list estab_space
			label define space_forgraph 1 "One room/ shop" 2 "Several rooms/ shops" ///
			3 "Half a floor in a building" 4 "One floor in a building" 5 "Several floors in a building" ///
           6 "An entire building" 7 "Several buildings"
			label values space space_forgraph
			
		graph hbar space_meansig space_meannosig, over(space, label(labsize(vsmall))) stack ///
				graphregion(color(white)) blabel(total, position(outside) format(%5.1f) color(white)  size(vsmall)) ///
				title("Space of Firms that Signed Up and Did not Sign Up", size(medium)) legend(label(1 "Signed Up") label(2 "Did not Sign Up")) ///
				subtitle("In Person Survey (Representative Sample) N = `nb_obs'", size(small)) ytitle("percentage") ///
				note("{it: Note: Question: ENUMERATOR: How much space does this establishment occupy?}" ///
				"Nb of Firms that Signed Up=`sign', Nb of firms that did not sign up=`nsign'" "This sample only consists of firms where respondent was successfully reached", size(vsmall))
				graph export "$graph_out\Firm Survey\Graphs\space_comp_sig_nsig.png", as(png) replace width(2400) height(1800)

restore


* (c) Turnover


preserve

gen turn_high = .
	replace turn_high = (jobs_rep_int_research/job_vac_int_research) * 100
	replace turn_high = (jobs_replace_inter/jobs_check_inter) * 100 if turn_high == .
	replace turn_high = 0 if (job_vac_int_research == 0 | jobs_check_inter == 0)

gen turn_low = .
	replace turn_low = (jobs_rep_mat_research/job_vac_mat_research) * 100
	replace turn_low = (jobs_replace_matric/jobs_check_matric) * 100 if turn_low == .
	replace turn_high = 0 if (job_vac_mat_research == 0 | jobs_check_matric == 0)

count if (!inlist(turn_high, .) & !inlist(turn_low, .))
	local nb_obs = `r(N)'

graph hbar (mean) turn_high turn_low, over(sig, label(labsize(vsmall))) nofill ///
graphregion(color(white)) ///
blabel(total, position(outside) format(%5.1f) color(black)  size(vsmall)) ///
	 title("% of Total Vacancies that were Replacements", size(medium))  legend(label(1 "Inter and Above") label(2 "Matric and Below") size(small)) ///
	subtitle("N = `nb_obs'", size(small)) ytitle("(replacement vacancies / total vacancies)*100") ///
	note("{it: Note: This Sample only consists of firms that signed up, participated in survey or answered research questions}" ///
	"Turnover %=Replacement Vacancies/Total Vacancies", size(vsmall))
	graph export "$graph_out\Firm Survey\Graphs\turnover.png", as(png) replace width(2400) height(1800)	 
	
restore


* (d) Average employee size


preserve
	keep if inlist(reg_status, 1, 9)

count
	local nb_obs=`r(N)'

	label drop pcsw_signup signup_service
	label val pcsw_signup sign
	label val signup_service sign

gen emp_cons=employee_size
	replace emp_cons=employee_number_research if emp_cons==.

graph hbar (mean) emp_cons, over(sig, label(labsize(vsmall))) nofill ///
graphregion(color(white)) $shades5 ///
blabel(total, position(outside) format(%5.1f) color(black)  size(vsmall)) ///
	 title("Average Employee Size", size(medium)) ///
	subtitle("N = `nb_obs'", size(small)) ytitle("# of employees (mean)") ///
	note("{it: Note: This Sample only consists of firms that signed up, participated in survey or answered research questions}", size(vsmall))
	graph export "$graph_out\Firm Survey\Graphs\emp_size.png", as(png) replace width(2400) height(1800)	

restore


****************************************************************************
*				(3) Transportation
****************************************************************************

* (a)	Transport Mode Used by Employees
	
	preserve
	foreach gender in male female {
		foreach mode in metrobus public rickshaw private employer onfoot {
		recode `mode'_`gender' (2=0)
		replace `mode'_`gender'=. if inlist(`mode'_`gender', 1111, 5555, 6666, 7777, 8888, 9999, .) 
		}
		ren metrobus_`gender' transport_`gender'_1
		ren public_`gender' transport_`gender'_2
		ren rickshaw_`gender' transport_`gender'_3
		ren private_`gender' transport_`gender'_4
		ren employer_`gender' transport_`gender'_5
		ren onfoot_`gender' transport_`gender'_6

		foreach i of numlist 1/6 { 
		sum transport_`gender'_`i'
		gen transport_`gender'_mean`i' = `r(mean)'*100
			}
			}
		keep transport_male_mean* transport_female_mean*
		duplicates drop

		gen helper = 1
		reshape long transport_male_mean transport_female_mean, i(helper) j(mode)
			
		label define transport 1 "Metrobus" 2 "Public bus" 3 "Rickshaw" ///
		4 "Car/Motorbike" 5 "Employer's pick and drop" 6 "On foot" 

		label values mode transport
			
		graph bar transport_female_mean transport_male_mean, over(mode, label(labsize(vsmall)) sort(1) descending) ///
		graphregion(color(white)) blabel(total, position(outside) format(%5.1f) color(black)  size(vsmall)) ///
		title("Transport mode used employees to commute to work", size(medium)) ytitle("% of firms") ///
		legend(label(1 "Female Employees") label(2 "Male Employees") size(small)) ///
		note("{it: Note: Question Do `gender' employees use the metrobus/use public buses or wagons/rickshaws or qingqis/cars of}" ///
		"{it:motorbikes/employer provided pick-and-drop/commute on foot to work at your organization?}.", size(vsmall)) 
		graph export "$graph_out\Firm Survey\Graphs\transport_fem_male.png", as(png) replace
		
	restore

	
* (b)	Consider transport mode and residence


preserve

label define residence_inter 1"Yes" 4"No"

	foreach var in residence_inter_cons transport_inter_cons {
	replace `var' = . if `var' > 4
	replace `var' = 1 if inlist(`var', 2, 3)
	label val `var' residence_inter
	}

	count if residence_inter_cons != . 
			local r_inter_n =`r(N)'


		catplot residence_inter_cons emplsize_cat, percent(emplsize_cat) stack asyvars ///
							recast(bar) graphregion(color(white)) ///
							var1opts(label(ang(45) labsize(3))) ///
							title("Consider Applicant Residence -- High Ed Jobs") subtitle("In Person Survey", size(medium)) b1title("") l1title("") ///
							ytitle("% of firms", size(small)) legend(size(small) cols(2))  ///
							note("{it: Note: Did you consider where candidates for this position resided within Lahore before filling this position? N = `r_inter_n'}", size(vsmall)) 
							graph export "$graph_out\Firm Survey\Graphs\applicant_residence_inter_firmsize.png", as(png) replace
			
			count if transport_inter_cons != . 
				local t_inter_n =`r(N)'
		
		catplot transport_inter_cons emplsize_cat, percent(emplsize_cat) stack asyvars ///
							recast(bar) graphregion(color(white)) ///
							var1opts(label(ang(45) labsize(3))) ///
							title("Consider Applicant Modes of Transport -- High Ed Jobs") subtitle("In Person Survey ", size(medium)) b1title("") l1title("") ///
							ytitle("% of firms", size(small)) legend(cols(2) size(small))  ///
							note("{it: Note: Did you consider the modes of tranport used by applicants to commute to work before filling this position? N = `t_inter_n'}", size(vsmall)) 
							graph export "$graph_out\Firm Survey\Graphs\applicant_transport_inter_firmsize.png", as(png) replace						

restore 

** availability of pick and drop service by firm size 

	preserve

		replace pick_and_drop = . if pick_and_drop > 3
		keep if signup_service == 1
		
		count if pick_and_drop != . 
				local pick_drop_n =`r(N)'
				
		catplot pick_and_drop emplsize_cat, percent(emplsize_cat) stack asyvars ///
							recast(bar) graphregion(color(white)) ///
							var1opts(label(ang(45) labsize(3))) ///
							$shades6 ///
							ytitle("% of firms", size(small)) legend(cols(3) size(small))  ///
							title("Pick and Drop Service Availability") subtitle("In Person Survey", size(medium)) b1title("") l1title("") ///
							note("{it: Question: Does your organization have a transport or pick-and-drop service? }", size(vsmall)) 


** contribute to cost of pick and drop by firm size
		count if cost_of_pick_and_drop != . 
				local pick_drop_n =`r(N)'
				
		catplot cost_of_pick_and_drop emplsize_cat, percent(emplsize_cat) stack asyvars ///
							recast(bar) graphregion(color(white)) ///
							var1opts(label(ang(45) labsize(3))) ///
							$shades6 ///
							ytitle("% of firms", size(small)) legend(cols(2) size(vsmall))  ///
							title("Consider Contributing to a Pick and Drop Service?") subtitle("In Person Survey", size(medium)) b1title("") l1title("") ///
							note("{it: Question: If a safe and reliable pick and drop service was made available to your employees, would you consider contributing to it?}", size(vsmall)) 


********************************************************************************
*				(4) Female Employees
********************************************************************************
* (a) Share of Female Employees by Firm Size
	preserve
		keep if sig == 1
		count
		local nb_obs = `r(N)'
			
		catplot female_employees emplsize_cat, percent(emplsize_cat) stack asyvars ///
		recast(bar) graphregion(color(white)) title("Share of female employees by firm size") ///
		$shades5 ///
		ytitle("% of female among employees", size(small)) legend(cols(3) size(small))  ///
		note("{it: Note: Question: Out of the employees who work at this location, how many are female? N =`nb_obs'.}", size(vsmall)) 
		graph export "$graph_out\Firm Survey\Graphs\fem_emp_firm_size.png", as(png) replace width(2400) height(1800)	
	
	restore
	
*(b)	Ads placed for women & firm composition
merge 1:m firm_id using "$anon_data\3ie Deliverable Datasets\FS_adlisting_public.dta"
keep if inlist(EB_type, 2)


	preserve
		keep if job_title_inter!=. | job_title_matric!=.

		distinct firm_id if add_vacancies == 1 & gender!=.
		local nb_ads = `r(N)'
		local nb_firms = `r(ndistinct)'
				
		gen female_cat = .
		replace female_cat = 0 if female_employees == 1
		replace female_cat = 1 if female_employees > 1
		lab define fem_emp 0 "No female employees" 1 "At least 1 female employee" 
		label values female_cat fem_emp
		
		label value gender gender
		
		catplot gender female_cat, percent(female_cat) stack asyvars ///
		recast(bar) graphregion(color(white)) title("Ads placed for women and current firm composition") ///
		ytitle("percent", size(small)) legend(cols(3))  ///
		note("{it: Note: Firm Survey Representative Sample. N ads = `nb_ads' and N firms = `nb_firms'.}", size(vsmall)) 
		graph export "$graph_out\Firm Survey\Graphs\fem_ad_placed.png", as(png) replace width(2400) height(1800)

	restore
	
	
*(c) Female Preference for Ads and Firm Size
	preserve
	
		keep if job_title_inter!=. | job_title_matric!=.
		
		
		distinct firm_id if add_vacancies == 1 & gender!=.
		local nb_ads = `r(N)'
		local nb_firms = `r(ndistinct)'
				
		gen female_cat = .
		replace female_cat = 0 if female_employees == 1
		replace female_cat = 1 if female_employees > 1
		lab define fem_emp 0 "No F employee" 1 "1+ F employee " 
		label values female_cat fem_emp

		replace female_employees = 4 if female_employees == 7
				label value gender gender
		
		catplot gender female_cat emplsize_cat, recast(bar) percent(emplsize_cat female_cat) stack asyvars ///
		graphregion(color(white)) title("Ads placed for women and current firm composition") subtitle("by firm size") ///
		ytitle("percent", size(small)) legend(cols(3))  var2opts(label(ang(30) labsize(2))) ///
		note("{it: Note: This sample consists of firms from the representative sample that listed ads with us. Current composition: 0 female employees, at least one. Firm size: number of}" "{it: employees. N ads = `nb_ads' and N firms = `nb_firms'.}", size(vsmall)) 
		graph export "$graph_out\Firm Survey\Graphs\fem_firm_ad_placed.png", as(png) replace width(2400) height(1800)
	
	restore
	
	
********************************************************************************
*				(5) Vacancies
********************************************************************************

*(a) Recruitment methods
		preserve
		
 keep if sig == 1
 
	distinct firm_id
		local nb_obs=`r(ndistinct)'

	distinct firm_id if !inlist(method_advertisment_matric_cons, ".", "", ".l")
		local low=`r(ndistinct)'

	distinct firm_id if !inlist(method_adv_inter_cons, ".", "", ".l")
		local high=`r(ndistinct)'

drop rec_mat_vac* rec_int_vac*

foreach i of numlist 1/6{
	gen rec_mat_vac`i'= 0
		replace rec_mat_vac`i'= . if inlist(method_advertisment_matric_cons, ".", "", ".l")
		replace rec_mat_vac`i'=1 if strpos(method_advertisment_matric_cons, "`i'")
	gen rec_int_vac`i'=0
		replace rec_int_vac`i'= . if inlist(method_adv_inter_cons, ".", "", ".l")
		replace rec_int_vac`i'=1 if strpos(method_adv_inter_cons, "`i'")
}


/// Calculating the %
foreach i of numlist 1/6{
	sum rec_mat_vac`i'
		gen mean_mat_vac`i'=`r(mean)'*100
	sum rec_int_vac`i'
		gen mean_int_vac`i'=`r(mean)'*100
}

	keep mean_*
	duplicates drop

gen helper=1
reshape long mean_int_vac mean_mat_vac, i(helper) j(method)


lab define rec 1 "Newspaper" 2 "Web job platform eg. Rozee"  3 "Third party sourcing" ///
4 "CV drop offs and walk-in interviews" 5 "College recruitment drive" 6	"Referral"

lab val method rec


graph hbar mean_int_vac, over(method, label(labsize(small))) ///
 $shades6 graphregion(color(white)) ///
blabel(total, position(outside) format(%5.1f) color(black)  size(vsmall)) ///
	 title("Recruitment Methods (high ed)", size(medium)) ///
	subtitle("Firms that signed up N = `nb_obs'", size(small)) ytitle("percentage") ///
	note("{it: Note: This sample only consists of firms that had a recent high-ed hire}" "Firms can have multiple recruitment methods" ///
	"Firms with a recent high-ed hire = `high'", size(vsmall))
	graph export "$graph_out\Firm Survey\Graphs\vac_rec_highed.png", as(png) replace width(2400) height(1800)	

graph hbar mean_mat_vac, over(method, label(labsize(vsmall))) ///
$shades6 graphregion(color(white)) ///
blabel(total, position(outside) format(%5.1f) color(black)  size(vsmall)) ///
	 title("Recruitment Methods (low-ed)", size(medium))  ///
	subtitle("Firms that signed up (Representative Sample) N = `nb_obs'", size(small)) ytitle("percentage") ///
	note("{it: Note: This sample only consists of firms that had}" "{it: a recent low-ed hire}" "Firms can have multiple recruitment methods" ///
	"Firms with a recent low-ed hire= `low'", size(vsmall))
	graph export "$graph_out\Firm Survey\Graphs\vac_rec_lowed.png", as(png) replace width(2400) height(1800)
restore
********************************************************************************
*			(6) Comparison of Recent Vacancy & Adlisting
********************************************************************************

	keep if ad_list == 1

// Lumping some of the education categories together

	recode edu_inter_cons_lab (42 = 40) (44 = 40) (46 = 40) (60 = 50) (70 = 50)
	recode edu_matric_cons_lab (42 = 40) (44 = 40) (46 = 40) (60 = 50) (70 = 50)
	recode deg_specify_lab (42 = 40) (44 = 40) (46 = 40) (60 = 50) (70 = 50)


* (a) Education


preserve

distinct firm_id
local nb_obs=`r(ndistinct)'
gen firm_tot=`r(ndistinct)'


count if edu_inter_cons_lab!= .
local high_vac = `r(N)'
gen high_vac = `r(N)'

count if edu_matric_cons_lab!= .
local low_vac = `r(N)'
gen low_vac = `r(N)'

egen tot_vac = rowtotal(high_vac low_vac)


foreach i of numlist 10 20 30 40 50 80 90 100 110{
			gen vac`i' = 0
			replace vac`i'=. if (edu_inter_cons_lab ==. & edu_matric_cons_lab==.)
			replace vac`i' = 1 if (edu_inter_cons_lab == `i' | edu_matric_cons_lab==`i')
			gen ad`i'=0
			replace ad`i'=. if deg_specify_lab == .
			replace ad`i'=1 if deg_specify_lab == `i'
			}
			 
			foreach i of numlist 10 20 30 40 50 80 90 100 110 { 
			count if vac`i' == 1
			gen vac_mean`i' = (`r(N)'/tot_vac)*100
			sum ad`i'
			gen ad_mean`i' = `r(mean)'*100
			}
			
			keep vac_mean* ad_mean*
			duplicates drop

			gen helper = 1
			reshape long vac_mean ad_mean, i(helper) j(deg)
			
		label define deg_forgraph 10 "None" 20 "Primary School" 30 "Middle School" 40 "Matriculation/O Level" ///
42	"Matriculation/O Level - Sciences" 44	"Matriculation/O Level - Computer Sciences" ///
46	"Matriculation/O Level - Arts" 50 "FSc /A Level" 60 "Fsc /A Level - Pre Engineering" ///
70 "F.A / A Level" 80 "Bachelors" 90 "Masters" 100 "PhD" 110 "Other Courses/Diplomas"

			label values deg deg_forgraph
graph hbar vac_mean ad_mean, over(deg, label(labsize(vsmall))) ///
				graphregion(color(white)) blabel(total, position(outside) format(%5.1f) color(black)  size(vsmall)) ///
				title("Comparison of Education in Recent Vacancy & Adlisting", size(medium)) ///
				legend(label(1 "Recent Vacancy Firm Hired for") label(2 "Ad placed by Firm on Job Talash") size(vsmall)) ///
				subtitle("Firms that listed ads and signed up N (Representative Sample)= `nb_obs'", size(small)) ytitle("percentage") ///
				note("{it: Note: This sample only consists of firms that listed ads and signed up from representative sample}", size(vsmall))
				graph export "$graph_out\Firm Survey\Graphs\vac_ad_ed.png", as(png) replace width(2400) height(1800)			
restore


*(b) Experience

preserve

	distinct firm_id
		local nb_obs =`r(ndistinct)'
	sum exp_matric_cons
		gen tot_exp_vac1=`r(mean)'

	sum exp_inter_cons
		gen tot_exp_vac2=`r(mean)'

	gen exp_req_inter=.
		replace exp_req_inter=exp_req if deg_specify_lab>=50
	sum exp_req_inter 
		gen tot_exp_ad2=`r(mean)'

	gen exp_req_mat=.
		replace exp_req_mat=exp_req if deg_specify_lab<=50
	sum exp_req_mat
		gen tot_exp_ad1=`r(mean)'

	keep tot_exp_*
	duplicates drop

	gen helper=1
	reshape long tot_exp_vac tot_exp_ad, i(helper) j(edu)

	label define edu 1 "Matric & below" 2 "Inter & above"
		lab val edu edu

	graph hbar tot_exp_vac tot_exp_ad, over(edu, label(labsize(vsmall))) ///
	 graphregion(color(white)) blabel(total, position(outside) format(%5.1f) color(black)  size(vsmall)) ///
		 title("Experience Required in Recent Vacancy and Adlisted", size(medium)) ///
		legend(label(1 "Recent Vacancy Firm Hired for") label(2 "Ad placed by firm with Job Talash") size(vsmall)) ///
		subtitle("Firms that listed ads and signed up N (Representative Sample)= `nb_obs'", size(small)) ytitle("mean") ///
		note("{it: Note: This sample only consists of firms that listed ads and signed up from the representative sample}", size(vsmall))
		graph export "$graph_out\Firm Survey\Graphs\vac_ad_exp.png", as(png) replace width(2400) height(1800)	
restore

*(c) Salary

preserve
	drop if job_intern==1 | job_trainee==1

	distinct firm_id
		local nb_obs=`r(ndistinct)'


	distinct firm_id if deg==1
		local high=`r(ndistinct)'
		gen high=`r(ndistinct)'
	distinct firm_id if deg==0
		local low=`r(ndistinct)'
		gen low=`r(ndistinct)'


foreach i of numlist 1/8{
	gen sal_mat_vac`i'= 0
		replace sal_mat_vac`i'= . if inlist(salary_matric_cons, ".", "", ".d", ".l", ".r")
		replace sal_mat_vac`i'=1 if strpos(salary_matric_cons, "`i'")
	gen sal_int_vac`i'=0
		replace sal_int_vac`i'= . if inlist(salary_inter_cons, "", ".", ".l", ".r")
		replace sal_int_vac`i'=1 if strpos(salary_inter_cons, "`i'")
	}
	

foreach i of numlist 1/8{
	gen sal_int_ad`i'=0
		replace sal_int_ad`i'=. if (inlist(job_pay, ".", "", ".d", ".u", ".r") | deg==0)
		replace sal_int_ad`i'=1 if (strpos(job_pay, "`i'") & deg==1)
	gen sal_mat_ad`i'=0
		replace sal_mat_ad`i'=. if (inlist(job_pay, ".", "", ".d", ".u", ".r") | deg==1)
		replace sal_mat_ad`i'=1 if (strpos(job_pay, "`i'") & deg==0)
}

local edu `" "int" "mat" "'

foreach x of local edu{
		replace sal_`x'_ad2 = 0 if sal_`x'_ad1 == 1
		replace sal_`x'_ad3 = 0 if sal_`x'_ad2 == 1
		replace sal_`x'_ad4 = 0 if sal_`x'_ad3 == 1
		replace sal_`x'_ad5 = 0 if sal_`x'_ad4 == 1
		replace sal_`x'_ad6 = 0 if sal_`x'_ad5 == 1
		replace sal_`x'_ad7 = 0 if sal_`x'_ad6 == 1
		replace sal_`x'_ad8 = 0 if sal_`x'_ad7 == 1
		replace sal_`x'_vac2 = 0 if sal_`x'_vac1 == 1
		replace sal_`x'_vac3 = 0 if sal_`x'_vac2 == 1
		replace sal_`x'_vac4 = 0 if sal_`x'_vac3 == 1
		replace sal_`x'_vac5 = 0 if sal_`x'_vac4 == 1
		replace sal_`x'_vac6 = 0 if sal_`x'_vac5 == 1
		replace sal_`x'_vac7 = 0 if sal_`x'_vac6 == 1
		replace sal_`x'_vac8 = 0 if sal_`x'_vac7 == 1
		
		}
		


foreach i of numlist 1/8{
	sum sal_mat_vac`i'
		gen mean_mat_vac`i'=`r(mean)'*100
	sum sal_int_vac`i'
		gen mean_int_vac`i'=`r(mean)'*100
	sum sal_mat_ad`i'
		gen mean_mat_ad`i'=`r(mean)'*100
	sum sal_int_ad`i'
		gen mean_int_ad`i'=`r(mean)'*100
}

	keep mean_*
	duplicates drop

gen helper=1
	reshape long mean_int_vac mean_int_ad mean_mat_vac mean_mat_ad, i(helper) j(salary)


	lab define sal 1"Under 10,000" 2"10,000-15,000" 3"15,000-20,000" 4"20,000-30,000" 5"30,000-50,000" 6"50,000-75,000" 7"75,000-100,000" 8"> 100,000"
		lab val salary sal

graph hbar mean_int_vac mean_int_ad, over(salary, label(labsize(vsmall))) ///
asyvars graphregion(color(white)) ///
blabel(total, position(outside) format(%5.1f) color(black)  size(vsmall)) ///
	 title("Salary Ranges (high ed)", size(medium)) ///
	 legend(label(1 "Recent Vacancy Firm Hired for") label(2 "Ad placed by firm with Job Talash") size(vsmall)) /// ///
	subtitle("Firms that listed ads and signed up (High ed & Representative Sample) N = `high'", size(small)) ytitle("percentage") ///
	note("{it: Note: This sample only consists of high-ed firms that listed}" "{it: jobs (not internships or traineeships) and signed up}" ///
	"Minimum salary of each job is included here", size(vsmall))
	graph export "$graph_out\Firm Survey\Graphs\vac_ad_sal_highed.png", as(png) replace width(2400) height(1800)	

graph hbar mean_mat_vac mean_mat_ad, over(salary, label(labsize(vsmall))) ///
asyvars graphregion(color(white)) ///
blabel(total, position(outside) format(%5.1f) color(black)  size(vsmall)) ///
	 title("Salary Ranges (low-ed)", size(medium)) ///
	 legend(label(1 "Recent Vacancy Firm Hired for") label(2 "Ad placed by firm with Job Talash") size(vsmall)) ///
	subtitle("Firms that listed ads and signed up (Low-ed & Representative Sample) N = `low'", size(small)) ytitle("percentage") ///
	note("{it: Note: This sample only consists of low-ed firms that listed}" "{it: jobs (not internships or traineeships) and signed up}" ///
	"Minimum salary of each job is included here", size(vsmall))
	graph export "$graph_out\Firm Survey\Graphs\vac_ad_sal_lowed.png", as(png) replace width(2400) height(1800)	

restore
